package com.csdj.newsmanger.service;

import com.csdj.newsmanger.dao.InformationsMapper;
import com.csdj.newsmanger.dao.RepliesMapper;
import com.csdj.newsmanger.vo.Informations;
import com.csdj.newsmanger.vo.Replies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationService {

    @Autowired(required = false)
    private InformationsMapper informationsMapper;

    @Autowired(required = false)
    private RepliesMapper repliesMapper;

    public List<Informations> queryAllInformation(){

        return informationsMapper.queryAllInformation();
    }

    /**
     * 根据编号 查询 新闻信息
     * @param id
     * @return
     */
    public Informations queryInformationById(Long id){

        return informationsMapper.selectByPrimaryKey(id);
    }

    /**
     * 根据 编号 查询 新闻的评论
     * @param id
     * @return
     */
    public List<Replies> queryAllRelies(Long id){

        return repliesMapper.queryRepliesAll(id);

    }

    /**
     * 添加评论
     * @param replies
     * @return
     */
    public int addRelies(Replies replies){

        return repliesMapper.insert(replies);
    }

    /**
     * 根据新闻编号 修改 回复数
     * @param id
     * @return
     */
    public int updateRelyCount(Long id){

        return informationsMapper.updateRelyCount(id);
    }

    /**
     * 根据新闻编号 修改查看数
     * @param id
     * @return
     */
    public int updateViewCount(Long id){
        return informationsMapper.updateViewcount(id);
    }

}
